package com.wmz.controller;

import com.wmz.domain.SysMenu;
import com.wmz.model.Result;
import com.wmz.service.SysMenuService;
import com.wmz.utils.AuthUtils;
import com.wmz.vo.MenuAndPermsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

/**
 * @author wmz
 * @date 2024/7/7 12:16
 * @description 系统权限控制层
 */
@Api(tags = "系统权限接口管理")
@RestController
@Slf4j
@RequestMapping("sys/menu")
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;

    @ApiOperation("查询用户的菜单权限和操作权限")
    @GetMapping("/nav")
    public Result<MenuAndPermsVO> loadUserMenuAndAuth(){
        // 获取用户信息
        Long userId = AuthUtils.getLoginUserId();
        // 获取权限集合
        Set<String> perms = AuthUtils.getPerms();
        // 获取菜单集合
        // 根据用户ID查询菜单集合
        Set<SysMenu> sysMenuSet = sysMenuService.queryUserMenus(userId);

        // 封装权限集合和菜单集合
        MenuAndPermsVO menuAndPermsVO = new MenuAndPermsVO(perms, sysMenuSet);
        return Result.success(menuAndPermsVO);
    }
}
